$(function () {
    // 判断是否可以进行下载
    var isDownLoad = $("#annexUpload").attr("is-down-load");
    var isLoadFile = $("#annexUpload").attr("load-file");
    if (!checkIsEmpty(isDownLoad) && isDownLoad == 1) {
        loadDownLoadFile();
    } else if (isLoadFile == 1) {
        loadFile();
    }

    //图片上传
    layui.use('upload', function () {
        var $ = layui.jquery, upload = layui.upload, uploadObj;
        var fileId = $('#annexUpload').attr("data-fileid");
        var fileId1 = $('#annexUpload1').attr("data-fileid");
        var fileId2 = $('#annexUpload2').attr("data-fileid");
        $.ajax({
            type: 'POST',
            url: sysInfo.basePath + '/annex/get_file_id.do',
            data: {fileId: fileId},
            dataType: 'json',
            success: function (result) {
                fileId = result.data;
                var type = $('#annexUpload').attr("data-type");
                upload.render({
                    elem: '#upload'
                    , url: sysInfo.gatewayFile + sysInfo.uploadFile
                    , multiple: true
                    , accept: 'file' //允许上传的文件类型
                    , size: 20 * 1024 //最大允许上传的文件大小
                    , data: {fileId: sysInfo.zzsc+"_"+fileId, type: type, isDeleteOriginalFile: false}
                    , before: function (obj) {
                        uploadObj = obj;
                        DGG.loading();
                    }
                    , done: function (res) {
                        if (res.code == 200) {
                            //预读本地文件示例，不支持ie8
                            uploadObj.preview(function (index, file, result) {
                                // 如果文件是图片格式
                                if (file.name == res.data.filename) {
                                    if (isImgFile(res.data.filename)) {
                                        $('#upload').parent().before('<li title=' + file.name + ' class="upload-li"><div class="data-img"><div class="center"><img src="' + result + '" class="layui-upload-img"></div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + file.name + '</p>' +
                                            '<input type="hidden" name="fileId" value="' + res.data.fileid + '">\n' +
                                            '<input type="hidden" name="fileName" value="' + res.data.filename + '"></li>')
                                    } else {
                                        $('#upload').parent().before('<li title=' + file.name + ' class="upload-li"><div class="data-img"><div class="center"><i class="text-file"></i></div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + file.name + '</p>' +
                                            '<input type="hidden" name="fileId" value="' + res.data.fileid + '">\n' +
                                            '<input type="hidden" name="fileName" value="' + res.data.filename + '"></li>')
                                    }
                                }


                            });
                            DGG.Succeed("上传成功");
                        } else {
                            DGG.Errors(res.msg);
                        }
                        DGG.loading('close');
                    }
                });
            }
        })
        $.ajax({
            type: 'POST',
            url: sysInfo.basePath + '/annex/get_file_id.do',
            data: {fileId: fileId1},
            dataType: 'json',
            success: function (result) {
                fileId = result.data;
                var type = $('#annexUpload1').attr("data-type");
                upload.render({
                    elem: '#upload1'
                    , url: sysInfo.gatewayFile + sysInfo.uploadFile
                    , multiple: true
                    , accept: 'file' //允许上传的文件类型
                    , size: 20 * 1024 //最大允许上传的文件大小
                    , data: {fileId: sysInfo.zzsc+"_"+fileId, type: type, isDeleteOriginalFile: false}
                    , before: function (obj) {
                        uploadObj = obj;
                        DGG.loading();
                    }
                    , done: function (res) {
                        if (res.code == 200) {
                            //预读本地文件示例，不支持ie8
                            uploadObj.preview(function (index, file, result) {
                                // 如果文件是图片格式
                                if (file.name == res.data.filename) {
                                    if (isImgFile(res.data.filename)) {
                                        $('#upload1').parent().before('<li title=' + file.name + ' class="upload-li"><div class="data-img"><div class="center"><img src="' + result + '" class="layui-upload-img"></div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + file.name + '</p>' +
                                            '<input type="hidden" name="fileId" value="' + res.data.fileid + '">\n' +
                                            '<input type="hidden" name="fileName" value="' + res.data.filename + '"></li>')
                                    } else {
                                        $('#upload1').parent().before('<li title=' + file.name + ' class="upload-li"><div class="data-img"><div class="center"><i class="text-file"></i></div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + file.name + '</p>' +
                                            '<input type="hidden" name="fileId" value="' + res.data.fileid + '">\n' +
                                            '<input type="hidden" name="fileName" value="' + res.data.filename + '"></li>')
                                    }
                                }


                            });
                            DGG.Succeed("上传成功");
                        } else {
                            DGG.Errors(res.msg);
                        }
                        DGG.loading('close');
                    }
                });
            }
        })
        $.ajax({
            type: 'POST',
            url: sysInfo.basePath + '/annex/get_file_id.do',
            data: {fileId: fileId2},
            dataType: 'json',
            success: function (result) {
                fileId = result.data;
                var type = $('#annexUpload2').attr("data-type");
                upload.render({
                    elem: '#upload2'
                    , url: sysInfo.gatewayFile + sysInfo.uploadFile
                    , multiple: true
                    , accept: 'file' //允许上传的文件类型
                    , size: 20 * 1024 //最大允许上传的文件大小
                    , data: {fileId: sysInfo.zzsc+"_"+fileId, type: type, isDeleteOriginalFile: false}
                    , before: function (obj) {
                        uploadObj = obj;
                        DGG.loading();
                    }
                    , done: function (res) {
                        if (res.code == 200) {
                            //预读本地文件示例，不支持ie8
                            uploadObj.preview(function (index, file, result) {
                                // 如果文件是图片格式
                                if (file.name == res.data.filename) {
                                    if (isImgFile(res.data.filename)) {
                                        $('#upload2').parent().before('<li title=' + file.name + ' class="upload-li"><div class="data-img"><div class="center"><img src="' + result + '" class="layui-upload-img"></div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + file.name + '</p>' +
                                            '<input type="hidden" name="fileId" value="' + res.data.fileid + '">\n' +
                                            '<input type="hidden" name="fileName" value="' + res.data.filename + '"></li>')
                                    } else {
                                        $('#upload2').parent().before('<li title=' + file.name + ' class="upload-li"><div class="data-img"><div class="center"><i class="text-file"></i></div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + file.name + '</p>' +
                                            '<input type="hidden" name="fileId" value="' + res.data.fileid + '">\n' +
                                            '<input type="hidden" name="fileName" value="' + res.data.filename + '"></li>')
                                    }
                                }


                            });
                            DGG.Succeed("上传成功");
                        } else {
                            DGG.Errors(res.msg);
                        }
                        DGG.loading('close');
                    }
                });
            }
        })
    });

    // 删除文件
    $(document).on('click', ".remove-upload", function () {
        var obj = $(this).parents(".upload-li");
        var fileId = obj.find('[name=fileId]').val();
        var fileName = obj.find('[name=fileName]').val();
        DGG.Confire("确定删除吗？", '删除提示', function () {
            $.post(sysInfo.gatewayFile + sysInfo.deleteFile, {fileId: fileId, fileName: fileName}, function (result) {
                if (result.code == 200) {
                    $.post(sysInfo.basePath + '/annex/del.do', {fileId: fileId, fileName: fileName}, function (result) {
                        if (result.code == 0) {
                            obj.remove();
                            DGG.Succeed("删除成功");
                        } else {
                            DGG.Errors("删除失败，请联系管理员");
                        }
                    })
                } else {
                    DGG.Errors("删除失败，请联系管理员");
                }
            }, 'json');
        });
    });
});


function loadFile() {
    var fileId = $('#annexUpload').attr("data-fileid");
    var type = $('#annexUpload').attr("data-type");
    var isMagnify = $('#annexUpload').attr("is-magnify");
    var isRemove = $("#annexUpload").attr("is-remove");
    $.post(sysInfo.basePath + "/annex/find_file.do", {fileId: fileId, type: type}, function (result) {
        if (result.code == 0) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // 判断是否可以进行删除
                var tag = "";
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = $('#upload').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                } else {
                    tag = $('#upload').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                }
                $('#upload').parent().before(tag);
            })
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    $.post(sysInfo.gatewayFile + sysInfo.getFileId, {fileId: sysInfo.zzsc+"_"+fileId+"_"+type, type: type}, function (result) {
        if (result.code == 200) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // 判断是否可以进行删除
                var tag = "";
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = $('#upload').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                } else {
                    tag = $('#upload').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                }
                $('#upload').parent().before(tag);
            })
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    var fileId1= $('#annexUpload1').attr("data-fileid");
    var type1 = $('#annexUpload1').attr("data-type");
    $.post(sysInfo.basePath + "/annex/find_file.do", {fileId: fileId1, type: type1}, function (result) {
        if (result.code == 0) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // 判断是否可以进行删除
                var tag = "";
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = $('#upload1').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                } else {
                    tag = $('#upload1').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                }
                $('#upload1').parent().before(tag);
            })
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    $.post(sysInfo.gatewayFile + sysInfo.getFileId, {fileId: sysInfo.zzsc+"_"+fileId1+"_"+type1, type: type1}, function (result) {
        if (result.code == 200) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // 判断是否可以进行删除
                var tag = "";
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = $('#upload1').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                } else {
                    tag = $('#upload1').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                }
                $('#upload1').parent().before(tag);
            })
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    var fileId2 = $('#annexUpload2').attr("data-fileid");
    var type2 = $('#annexUpload2').attr("data-type");
    $.post(sysInfo.basePath + "/annex/find_file.do", {fileId: fileId2, type: type2}, function (result) {
        if (result.code == 0) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // 判断是否可以进行删除
                var tag = "";
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = $('#upload2').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                } else {
                    tag = $('#upload2').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                }
                $('#upload2').parent().before(tag);
            })
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    $.post(sysInfo.gatewayFile + sysInfo.getFileId, {fileId: sysInfo.zzsc+"_"+fileId2+"_"+type2, type: type2}, function (result) {
        if (result.code == 200) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // if(e.createUser==null){
                //     e.createUser="";
                // }
                // 判断是否可以进行删除
                var tag = "";
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = $('#upload2').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                } else {
                    tag = $('#upload2').parent().before('<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '"></li>');
                }
                $('#upload2').parent().before(tag);
            });
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
}


function loadDownLoadFile() {
    var fileId = $('#annexUpload').attr("data-fileid");
    var type = $('#annexUpload').attr("data-type");
    var isRemove = $("#annexUpload").attr("is-remove");
    var isMagnify = $('#annexUpload').attr("is-magnify");
    $.post(sysInfo.basePath + "/annex/find_file.do", {fileId: fileId, type: type}, function (result) {
        if (result.code == 0) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // if(e.createUser==null){
                //     e.createUser="";
                // }
                var tag = "";
                // 判断是否可以进行删除
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p >下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                } else {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p>下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                }
                $('#upload').parent().before(tag);
            });
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    $.post(sysInfo.gatewayFile + sysInfo.getFileId, {fileId: sysInfo.zzsc+"_"+fileId+"_"+type, type: type}, function (result) {
        if (result.code == 200) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // if(e.createUser==null){
                //     e.createUser="";
                // }
                var tag = "";
                // 判断是否可以进行删除
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p >下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                } else {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p>下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                }
                $('#upload').parent().before(tag);
            });
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    var type1 = $('#annexUpload1').attr("data-type");
    $.post(sysInfo.basePath + "/annex/find_file.do", {fileId: fileId, type: type1}, function (result) {
        if (result.code == 0) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // if(e.createUser==null){
                //     e.createUser="";
                // }
                var tag = "";
                // 判断是否可以进行删除
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p >下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                } else {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p>下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                }
                $('#upload1').parent().before(tag);
            });
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    $.post(sysInfo.gatewayFile + sysInfo.getFileId, {fileId: sysInfo.zzsc+"_"+fileId+"_"+type1, type: type1}, function (result) {
        if (result.code == 200) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // if(e.createUser==null){
                //     e.createUser="";
                // }
                var tag = "";
                // 判断是否可以进行删除
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p >下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                } else {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p>下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                }
                $('#upload1').parent().before(tag);
            });
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    var type2 = $('#annexUpload2').attr("data-type");
    $.post(sysInfo.basePath + "/annex/find_file.do", {fileId: fileId, type: type2}, function (result) {
        if (result.code == 0) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // if(e.createUser==null){
                //     e.createUser="";
                // }
                var tag = "";
                // 判断是否可以进行删除
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p >下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                } else {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p>下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                }
                $('#upload2').parent().before(tag);
            });
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
    $.post(sysInfo.gatewayFile + sysInfo.getFileId, {fileId: sysInfo.zzsc+"_"+fileId+"_"+type2, type: type2}, function (result) {
        if (result.code == 200) {
            $.each(result.data, function (i, e) {
                var imgTag = '<i class="text-file"></i>';
                if (isImgFile(e.filename)) {
                    imgTag = '<img src="' + e.filepath + '" alt="加载中" class="layui-upload-img">';
                }
                // if(e.createUser==null){
                //     e.createUser="";
                // }
                var tag = "";
                // 判断是否可以进行删除
                if (!checkIsEmpty(isRemove) && isRemove == 0) {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p >下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                } else {
                    tag = '<li title=' + e.filename + ' class="upload-li"><div class="data-img"><div class="center">' + imgTag + '</div><a href="javascript:void(0)" class="remove-upload"></a></div><p>' + e.filename + '</p>' +
                        '<input type="hidden" name="fileId" value="' + e.fileid + '">\n' +
                        '<input type="hidden" name="fileName" value="' + e.filename + '">\n' +
                        '<button type="button" class="layui-btn layui-btn-mini" onclick="downLoadFile(this,\'' + e.fileid + '\',\'' + e.filepath + '\',\'' + e.filename + '\')">下载文件</button>' +
                        // ' <p>下载次数：<span name="downLoadTimes">' + e.downCount + '</span></p>' +
                        // ' <p><span name="createUser" title="'+e.createUser+'">' + e.createUser + '</span></p>' +
                        ' <p><span name="filedate">' + e.filedate + '</span></p>' +
                        '</li>';
                }
                $('#upload2').parent().before(tag);
            });
            // 是否可以放大查看图片
            if (!checkIsEmpty(isMagnify) && isMagnify == 1) {
                layer.photos({
                    photos: '#previewImg'
                    , anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                });
            }
        } else {
            DGG.Errors(result.msg);
        }
    });
}

/**
 * 下载文件
 * @param obj
 */
function downLoadFile(obj, fileId, fileUrl, fileName) {
    window.location.href = sysInfo.basePath + "/annex/download.do?id=" + fileId + "&fileUrl=" + fileUrl + "&fileName=" + fileName;
    var downLoadTims = $(obj).parent().find("[name='downLoadTimes']").html();
    $(obj).parent().find("[name='downLoadTimes']").html(parseInt(downLoadTims) + 1);
}

/**
 * 统计查看次数
 * @param obj
 * @param fileId
 */
function viewFileCount(obj) {
    var fileId = obj.find('[name=fileId]').val();
    var fileName = obj.find('[name=fileName]').val();
    $.post(sysInfo.basePath + "/annex/view_file.do", {id: fileId, fileName: fileName}, function (result) {
    });
}

/**
 * 判断是否是图片
 * @param filepath
 * @returns {boolean}
 */
function isImgFile(filepath) {
    var extStart = filepath.lastIndexOf(".");
    var ext = filepath.substring(extStart, filepath.length).toUpperCase();
    return (ext == ".BMP" || ext == ".PNG" || ext == ".GIF" || ext == ".JPG" || ext == ".JPEG");
}